<?php

// 获取会员分页列表
// GET member.admin.volist

namespace app\api\resource\member\admin;
use think\Db;
use app\api\lib\Page;

class Volist
{
    // 方法
    public $_method = ['GET'];
    // 前置
    public $_pre    = ['adminLogin'];
    // 描述
    public $_description = '获取会员分页列表';
    // 参数
    public $_param  = [
        'page'  => '请求页,默认1',
        'show'  => '请求记录数量,默认10',
        'model' => '模式,0-全部(默认) 1-待审核 2-已锁定',
        'role'  => '角色,0-全部(默认) 1-创业者 2-投资者',
        'skey'  => '搜索关键词,手机号',
    ];
    // 返回
    public $_return = [
        200 => '获取成功',
    ];

    public function run(&$request)
    {
        $page  = $request->get('page/d',1);
        $show  = $request->get('show/d',10);

        $model = $request->get('model/d',0);
        $role  = $request->get('role/d',0);
        $skey  = $request->get('skey/s','','trim');

        $table = 'member';
        $where = '';

        // 模式
        if (1 == $model) {
            $where['status'] = 9;
        } elseif (2 == $model) {
            $where['status'] = 1;
        }
        // 角色
        if (1 == $role) {
            $where['role'] = 1;
        } elseif (2 == $role) {
            $where['role'] = ['>',1];
        }
        // 搜索关键词
        if ( !empty($skey) ) {
            $where['mobile'] = ['like','%' . $skey . '%'];
        }

        $list = Db::name($table)->where($where)->order('id desc')->page($page,$show)->select();

        // 填装个人信息
        if ( !empty($list) ) {
            foreach ($list as $key => $val) {
                $list[$key]['info'] = Db::name('member_info')->where('member_id',$val['id'])->find();
                if ($val['role'] > 1) {
                    $list[$key]['card'] = Db::name('member_like')->where('member_id',$val['id'])->value('card');
                }
            }
        }

        $pagelist = Page::run($table,$page,$show,$where,$list);

        return [200,$pagelist];
    }
}
